function [finishMovePackets, primarySender, primaryReceiver, primaryPath, trafficBuffer, disp_loc, matrix, f] =  movePackets (trafficBuffer, primaryPathTable, finishingTime, disp_loc, R, noOfNodes,networkSize,velocity, thetaBuffer, f, matrix)
    
    pr = size(primaryPathTable, 2); 
    TB = length(trafficBuffer);
    primaryPath = 1; 
    primarySender = 0;
    primaryReceiver = 0;
    destination = primaryPathTable(pr);
    TSsBuffer = zeros(1,1);
    TSsBuffer1 = zeros(1,1);
    TSsBuffer2 = zeros(1,1);
        
    counter1 = 1;
    counter2 = 1;
    
        for i = 1:TB
            sender = trafficBuffer(i,1);
            oddEvenNodes = mod(i, 2);
            if oddEvenNodes ~= 0 && sender ~= destination
                TSsBuffer1(counter1) = sender;
                counter1 = counter1 +1;
            elseif oddEvenNodes == 0 &&  sender ~= destination
                TSsBuffer2(counter2) = sender;
                counter2 = counter2 +1;
            end            
        end
    
    sourcePackets = trafficBuffer(1,2);
    currentDestinationPackets = 0;
    finishMovePackets = 1;
    turnTS = 1;
    while finishMovePackets == 1   
        counter = 1;
        turnTSs = mod(turnTS, 2);
        turnTS = turnTS + 1;
        TSsBuffer = 0;
        if turnTSs ~= 0
            TB1 = length(TSsBuffer1);
            for i = 1:TB1
                node1 = TSsBuffer1(i);
                for j = 1:TB
                    node2 = trafficBuffer(j, 1);
                    if node1 == node2 && trafficBuffer(j, 2) ~=0
                        TSsBuffer(counter) = node1;
                        counter = counter + 1;
                    end
                end
            end
        else
            TB2 = length(TSsBuffer2);
            for i = 1:TB2
                node1 = TSsBuffer2(i);
                for j = 1:TB
                    node2 = trafficBuffer(j, 1);
                    if node1 == node2 && trafficBuffer(j, 2) ~=0
                        TSsBuffer(counter) = node1;
                        counter = counter + 1;
                    end
                end
            end
        end
        
        
        TS = length(TSsBuffer);
        time = toc;
        t = time - finishingTime;
        finishingTime = time;
        if t > 10 
             f = f + 1;
             figure(f); 
             clf;
             hold on  
            % We should move the nodes here.
            [disp_loc, matrix] = moveNodes(noOfNodes,networkSize,R,disp_loc, velocity, thetaBuffer);
            [primaryPath, primarySender, primaryReceiver] = checkingAvailabilityOfPath(primaryPathTable, disp_loc, R);   
            [connected] = checkConnectedGraph(disp_loc, matrix);
                     if connected == 1
                         disp('That graph number');
                         disp(f);
                         disp('Is connected');
                     else
                         disp('That graph number');
                         disp(f);
                         disp('Is not connected');         
                     end        
        end
        if primaryPath ~= 0
            for i = 1:TS
                    sndInTS = TSsBuffer(i); 
                    for j = 1:TB
                        sndInPrimary = primaryPathTable(j);
                        if sndInTS == sndInPrimary && sndInPrimary ~= destination
                            for k = 1:TB
                                sndBuffer = trafficBuffer(k,1);                        
                                if sndInPrimary == sndBuffer && trafficBuffer(k,2)~= 0 && sndBuffer ~= destination                            
                                    trafficBuffer(k,2)= trafficBuffer(k,2) - 1;
                                     k1 = k + 1;                             
                                     trafficBuffer(k1,2)= trafficBuffer(k1, 2) + 1;                                      
                                end  
                            end
                        end   
                    end
            end 
        else 
            finishMovePackets = 0;             
        end
        n = pr - 1;
        numberPackets = trafficBuffer(1,2);
        for i = 2:n
            numberPackets1 =  trafficBuffer(i,2);
            numberPackets = numberPackets + numberPackets1;
        end
        if  numberPackets == 0
            finishMovePackets = 0;
        end
        
    end     
end